<?php
require $root."/LinkedList/LinkedList.php";
$linkedList = new LinkedList();

for ($i = 1;$i <= 10;$i++){
    $linkedList->addFirst($i);
}
echo $linkedList->toString();
echo "\n";
/**
 * 链表翻转循环写法
 */
function turn($head){
    $pre = $head;
    $cur = $pre->next;
    while($cur){
        $next = $cur->next;
        $cur->next = $pre;
        $pre = $cur;
        $cur = $next;
    }

    $head->next = null;
    return $pre;
}
/**
 * 链表翻转递归写法
 */
function recursion($head){
    if($head->next == null){
        return $head;
    }

    $pre = $head;
    $next = recursion($head->next);
    $head->next->next = $head;
    $head->next  = null;
    return $next;
}

print_r(recursion($linkedList->getHead()));










